index = int(len(svm_data) * 0.6)
train_labels = []
train_samples = []

# ==== TRAIN DATA ====
for i in svm_data[:index]:
    train_labels.append(i[0])
    train_samples.append(i[1])


problem = svm_problem(train_labels, train_samples)
param = svm_parameter(kernel_type= LINEAR, C = 10, probability = 1) #, nr_weight = 2, weight_label = [1,0], weight = [10,1],
#param = svm_parameter(svm_type = C_SVC, kernel_type = LINEAR, probability = 1)
model = svm_model(problem,param)

# ==== CA ====
correct = 0
truePositive = 0
myPositive = 0
allPositive = 0

for i in svm_data[index:]:
    pred = model.predict_probability(i[1])
    #print i[0], pred
    # ca
    if i[0] == pred[0]:
        correct += 1
    # precision, Kolikokrat sem rekel, da ima nekdo bolezen
    if pred[0] == 1:
        myPositive += 1
        # Kolikokrat sem pravilno rekel, da ima nekdo bolezen
        if i[0] == pred[0] == 1:
            truePositive += 1
    # recall, Kolikokrat bi moral, reci, da ima nekdo bolezen
    if i[0] == 1:
        allPositive += 1

ca = correct / float(len(svm_data[index:]))
precision = truePositive / float(myPositive)
recall = truePositive / float(allPositive)

print "CA:", ca
print "Precision:", precision
print "recall:", recall
print "F1:", 2 * ((precision * recall) / (precision + recall))
